FROM centos

# create slurm user
RUN export MUNGEUSER=991 && \
    groupadd -g $MUNGEUSER munge && \
    useradd  -m -c "MUNGE Uid 'N' Gid Emporium" -d /var/lib/munge -u $MUNGEUSER -g munge  -s /sbin/nologin munge && \
    export SLURMUSER=992 && \
    groupadd -g $SLURMUSER slurm && \
    useradd  -m -c "SLURM workload manager" -d /var/lib/slurm -u $SLURMUSER -g slurm  -s /bin/bash slurm

RUN yum install -y mod_wsgi httpd-devel python-ldap python-redis dejavu-sans-mono-fonts clustershell python-flask Cython npm python-devel git

# slurm-web js & css
RUN mkdir -p /opt/slurmweb
COPY ./slurmweb /opt/slurmweb

# install pip
RUN yum install -y epel-release && \
    yum install -y python2-pip && \
    pip install -U pip

# copy slurm-rpms
RUN mkdir -p /opt/slurmweb/slurm-rpms
COPY ./slurm-rpms /opt/slurmweb/slurm-rpms

# install slurm-libs
RUN yum install -y munge munge-libs munge-devel openssl openssl-devel pam-devel numactl numactl-devel hwloc hwloc-devel lua lua-devel readline-devel rrdtool-devel ncurses-devel man2html libibmad libibumad perl-ExtUtils-MakeMaker gcc mariadb-server mariadb-devel perl-Switch

# install slurm
RUN cd /opt/slurmweb/slurm-rpms && \
    rpm -i *


# install pyslurm
RUN cd /opt/slurmweb/src/pyslurm && \
    /bin/python setup.py build && \
    /bin/python setup.py install

# install slurm-web
RUN cd /opt/slurmweb/src/slurm-web && \
    /bin/install -d /opt/slurmweb/www/html/slurm-web && \
    /bin/install -d /opt/slurmweb/etc/slurm-web && \
    cd /usr/share && \
    ln -s /opt/slurmweb/www/html/slurm-web && \
    cd /etc && \
    ln -s /opt/slurmweb/etc/slurm-web

# install dashboard
RUN /bin/install -d /usr/share/slurm-web/dashboard/js && \
    /bin/install -d /usr/share/slurm-web/dashboard/css && \
    /bin/install -d /usr/share/slurm-web/dashboard/static && \
    cd /opt/slurmweb/src/slurm-web && \
    /bin/cp -ar dashboard/html/* /usr/share/slurm-web/dashboard && \
    /bin/cp -ar dashboard/js/* /usr/share/slurm-web/dashboard/js && \
    /bin/cp -ar dashboard/css/* /usr/share/slurm-web/dashboard/css && \
    /bin/cp -ar dashboard/static/* /usr/share/slurm-web/dashboard/static

# install restapi
RUN /bin/install -d /usr/share/slurm-web/restapi/schema/dtd && \
    cd /opt/slurmweb/src/slurm-web && \
    /bin/cp -ar rest/*.py rest/*.wsgi /usr/share/slurm-web/restapi && \
    /bin/cp -ar schema/racks.dtd /usr/share/slurm-web/restapi/schema/dtd

# config conf-server
RUN /bin/install -d /usr/share/slurm-web/conf-server && \
    cd /opt/slurmweb/src/slurm-web && \
    /bin/cp -ar conf/dashboard/* /usr/share/slurm-web/conf-server && \
    /bin/cp -ar dashboard/backend/* /usr/share/slurm-web/conf-server && \
    /bin/install -m644  dashboard/backend/slurmwebconf.py dashboard/backend/slurm-web-conf.wsgi  /usr/share/slurm-web/conf-server && \
    /bin/install -m644 conf/racks.xml /etc/slurm-web && \
    /bin/install -m644 conf/restapi.conf /etc/slurm-web

# install clustershell
RUN pip install clustershell
RUN yum install -y python-redis

ADD ./slurm-web.conf /etc/httpd/conf.d/slurm-web.conf
ADD ./config.json /usr/share/slurm-web/conf-server/config/json
ADD ./slurm-web-restapi.wsgi /usr/share/slurm-web/restapi/slurm-web-restapi.wsgi
ADD ./javascript.conf /etc/httpd/conf.d/javascript.conf
ADD ./munge.sh /opt/munge.sh
RUN chmod +x /opt/munge.sh

ADD ./run.sh /opt/run.sh
RUN chmod +x /opt/run.sh
ENTRYPOINT ["/opt/run.sh"]
EXPOSE 80
